#include "walbum.h"

WAlbum::WAlbum(QWidget *parent) :
    WTable(parent)
{
    tableView->setModel(&model);
    tableView->setColumnWidth(DtAlbum::Name, 300);
    tableView->setColumnWidth(DtAlbum::Play, 30);
    tableView->setColumnWidth(DtAlbum::Add, 30);
    tableView->setColumnWidth(DtAlbum::Heart, 30);
    tableView->setColumnWidth(DtAlbum::Year, 60);
    tableView->setColumnWidth(DtAlbum::Cover, 30);
    connect(tableView, SIGNAL(clicked(QModelIndex)), this,
            SLOT(on_tableView_clicked(QModelIndex)));
}

WAlbum::~WAlbum()
{
}

QString WAlbum::getPath()
{
    return selection;
}

void WAlbum::setList(QList<AbstractData *> &lAlbum)
{
    model.setList((QList<DtAlbum *> &)lAlbum);
}

void WAlbum::on_tableView_clicked(const QModelIndex &index)
{
    if(!index.isValid())
        return;
    if(index.column() == DtAlbum::Play || index.column() == DtAlbum::Add
            || index.column() == DtAlbum::Heart)
    {
        selection = "";
        model.getList()[index.row()]->clicked(index.column());
        if(index.column() == DtAlbum::Play)
        {
            emit playAlbum(model.getList()[index.row()]->getTracks());
        } else if(index.column() == DtAlbum::Add)
        {
            emit addAlbum(model.getList()[index.row()]->getTracks());
        }
    }
    else if (index.column() == DtAlbum::Name)
    {
        selection = model.getList()[index.row()]->getName();
        emit navigateToTracks((QList<AbstractData *> &)model.getList()
                              [index.row()]->getTracks());
    }
}

void WAlbum::on_tableView_doubleClicked(const QModelIndex &index)
{
    if(!index.isValid())
        return;
}
